<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>投诉处理</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>

<blockquote class="layui-elem-quote news_search">
    <form class="layui-form">
        <div style="margin-top: 1%">
            <div class="layui-input-inline">
                <input type="text" id="username" value="" placeholder="请输入昵称"
                       class="layui-input search_input">
            </div>
            <div class="layui-inline">
                <input type="text" id="begin"
                       class="layui-input userName" name="begin"
                       placeholder="注册时间(开始)" value="">
            </div>
            <div class="layui-inline">
                <input type="text" id="end" class="layui-input userName"
                       name="end" placeholder="注册时间(结束)" value="">
            </div>
            <a class="layui-btn layui-btn-disabled" shiro:lacksPermission="ts:ts:list">查询</a>
            <a class="layui-btn search_btn" lay-submit="" data-type="search"
               lay-filter="search" shiro:hasPermission="ts:ts:list">查询</a>
            <div class="layui-inline">（支持模糊查询）</div>
        </div>
    </form>
</blockquote>

    <table id="ts" lay-filter="test"></table>

<script type="text/html" id="barEdit">
    <a class="layui-btn layui-btn-xs layui-btn-disabled" shiro:lacksPermission="ts:ts:update">处理</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit" shiro:hasPermission="ts:ts:update">处理</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" shiro:lacksPermission="ts:ts:delete">删除</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" shiro:hasPermission="ts:ts:delete">删除</a>
</script>


    <script th:src="@{/src/layui.js}"></script>
    <script>
        //layui基于组件(模块)开发的     ctrl+shift+f9  工具中重构代码
        layui.use(['table','laydate','jquery','layer'],function () {
            var table = layui.table;
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var layer = layui.layer;
            table.render({
                elem:'#ts',
                url:'/ts/list',
                page:true,
                limit:5,
                limits:[5,10,15],
                cols:[
                    [
                        {field:'tUser',title:'用户'},
                        {field:'tContent',title:'投诉内容'},
                        {field:'tTime',title:'投诉时间'},
                        {field:'tStatus',title:'投诉状态'},
                        {title:'操作',width:200,templet:'#barEdit'}
                    ]
                ],
                parseData:function (res) {
                    return {
                        "code":res.code==200?0:res.code,
                        "msg":res.message,
                        "count":res.data.total,
                        "data":res.data.list
                    }
                }
            })

            //日期控件
            var start = laydate.render({
                elem:'#begin',
                max:'new Date()',
                done:function (value,date) {
                    end.config.min = date
                    end.config.min.month = date.month-1;  //js  ==> var d  =new Date(); alert( d.getMonth()); 0-11
                }
            });

            var end = laydate.render({
                elem:'#end',
                max: 'new Date()',
                done:function (value,date) {
                    start.config.max = date;
                    start.config.max.month = date.month-1;
                }
            })
            //搜索
            $(".search_btn").click(function () {
                table.reload('ts', {
                    url: '/ts/list'
                    ,where: {
                        username: $("#username").val(),
                        begin:$("#begin").val(),
                        end:$("#end").val()
                    } //设定异步数据接口的额外参数
                });
            })

            
            table.on('tool(test)',function (obj) {
                var data = obj.data;//行数据
                alert(data.tid);
                var event = obj.event;
                if(event === 'edit'){
                    layer.open({
                        type:2,
                        title:'处理投诉',
                        area:['500px','500px'],
                        content:'/ts/toCts/'+data.tid
                    });
                }else if(event === 'del'){
                    layer.confirm('确认删除？',function (index) {
                        $.ajax({
                            url:'/ts/deleteTs/'+data.tid,
                            type:'delete',
                            dataType:'json',
                            success:function (res) {
                                if(res.code == 200){
                                    layer.msg('删除成功',{icon:1},function () {
                                        location.reload();
                                    })
                                }else{
                                    layer.msg('删除失败',{icon:5})
                                }
                            }
                        })

                        layer.close(userList);
                    })
                }
            })

        })
    </script>

</body>
</html>